﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ImpactTenis.AcessoADados.DTOs;
using System.Configuration;
using System.Data.SqlClient;

namespace ImpactTenis.AcessoADados.Cores
{
    public class CoresDados
    {
        private string _connectionString { get; set; }

        public CoresDados() 
        {
            _connectionString = ConfigurationManager.ConnectionStrings["ImpactTenis"].ConnectionString;
        }

        public List<CoresDTO> CarregaCores() 
        {
            try 
            {
                using (var conexao = new SqlConnection(_connectionString))
                {
                    string commandText = "SELECT * FROM tbl_Cores";
                    var command = new SqlCommand(commandText, conexao);

                    var cores = new List<CoresDTO>();
                    conexao.Open();

                    using (var reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            cores.Add(new CoresDTO {
                                Id = Convert.ToInt32(reader["Id"].ToString()),
                                Descricao = reader["Descricao"].ToString()
                            });
                            
                        }
                    }
                    return cores;
                }
            }
            catch
            {
                throw new Exception("Não foi possível carregar as cores");
            }
        }
    }
}
